package com.aco.party.common.util;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * properties文件操作类
 * <P>Title: PropertiesUtils</P>
 * <P>Description: create by XSDToJava V1.0</P>
 * <P>Copyright: Copyright (c) 2013 </P>
 * <P>Company: xunzuo </P>
 * 
 * @author clj
 * @version 1.0
 * @create 2013-9-20
 * @history
 */
public class PropertiesUtils {
	private static final Logger logger = LoggerFactory
			.getLogger(PropertiesUtils.class);

	/**
	 * 读取和遍历properties文件
	 * 
	 * @param fileName
	 * @return
	 * @throws FileNotFoundException
	 */
	public static Map<String, String> getPropertiesMap(String fileName)
			throws FileNotFoundException {
		Map<String, String> propMap = new HashMap<String, String>();
		Properties prop = new Properties();
		InputStream in = new BufferedInputStream(new FileInputStream(fileName));
		try {
			prop.load(in);
			Set<Object> keyset = prop.keySet();
			for (Object object : keyset) {
				String propValue = prop.getProperty(object.toString())
						.toString();
				propMap.put(object.toString(), propValue);
			}
		} catch (IOException e) {
			logger.error("getPropertiesMap 异常" + e.getMessage(), e);
		} finally {
			try {
				in.close();
			} catch (IOException e) {
				logger.error("getPropertiesMap close 异常" + e.getMessage(), e);
			}
		}
		return propMap;
	}
}
